'######################################################################################
'Author  :         Sumit Gupta 
'Company :				 Vikasumit
'Date    :         9th July 2005
'--------------------------------------------------------------------------------------
'Working / Note on File : 
'Define the Position that can be achieve on the board of Chess Game
'The value of Position can be define in Chess Notation or in Numeric Notation from
'1-8 or a-h, It is taken that a1 is the White rook and White King falls on the e1 position
'and Black on e8 position
'######################################################################################

Public Class clsPosition

#Region "Private Variable"
	Private t_x As Integer
	Private t_y As Integer
  Private Const CON_CLASSVERSION As String = "1.0.20050709"  'Define the Class Version
#End Region

#Region "Public Porperty"

	'Get the Class Version
	Public ReadOnly Property ClassVersion() As String
		Get
			Return CON_CLASSVERSION
		End Get
	End Property

	Public Property X() As Integer
		Get
			Return t_x
		End Get
		Set(ByVal Value As Integer)
      If Value < 0 Then Value = 0
      If Value > 7 Then Value = 7
      t_x = Value
		End Set
	End Property

	Public Property Y() As Integer
		Get
			Return t_y
		End Get
		Set(ByVal Value As Integer)
      If Value < 0 Then Value = 0
      If Value > 7 Then Value = 7
      t_y = Value
		End Set
	End Property

#End Region

#Region "Public Function and Constructor"

	Public Sub New()
    t_x = 0
    t_y = 0
	End Sub

	Public Sub New(ByVal xPos As Integer, ByVal yPos As Integer)
    If xPos < 0 Then xPos = 0
    If xPos > 7 Then xPos = 7
    If yPos < 0 Then yPos = 0
    If yPos > 7 Then yPos = 7
    t_x = xPos
    t_y = yPos
	End Sub

	Public Sub New(ByVal xPos As Char, ByVal yPos As Char)
		t_x = GetNumericPos(xPos)
		t_y = GetNumericPos(yPos)
	End Sub

	Public Sub New(ByVal Makeas As clsPosition)
		t_x = Makeas.X
		t_y = Makeas.Y
	End Sub


	Public Function IsEqualTo(ByVal Pos As clsPosition) As Boolean
		If t_x = Pos.X AndAlso t_y = Pos.Y Then
			Return True
		Else
			Return False
		End If
	End Function

	Public Sub CopyAs(ByVal Pos As clsPosition)
		Me.X = Pos.X
		Me.Y = Pos.Y
	End Sub

#End Region

#Region "Private Function}"

	Private Function GetNumericPos(ByVal Pos As Char) As Integer
		'Check if it is a-h or A-H
		Pos = LCase(Pos)
    Select Case CStr(Pos)
      Case "a"
        Return 0
      Case "b"
        Return 1
      Case "c"
        Return 2
      Case "d"
        Return 3
      Case "e"
        Return 4
      Case "f"
        Return 5
      Case "g"
        Return 6
      Case "h"
        Return 7
      Case Else
        Return 0
    End Select
	End Function

#End Region

End Class